﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuanLyThuVien.Business;

namespace QuanLyThuVien.DataAccess
{
    class NXBDAL
    {
        clsDatabase db = new clsDatabase();
        public void ThemMoiNXB(NXB NXB)
        {
            db.ThuThiSQL("insert into tbNXB values(N'"+NXB.MaNXB+"',N'" + 
                NXB.TenNXB + "',N'" +
                NXB.DiaChi + "',N'" +
                NXB.DienThoai + "')");
        }

        public void SuaNXB(NXB NXB)
        {
            db.ThuThiSQL("update tbNXB set TenNXB=N'" + NXB.TenNXB + "',DiaChi=N'" + NXB.DiaChi + "',SDT=N'" + NXB.DienThoai + "'where MaNXB=N'" + NXB.MaNXB + "'");
        }

        public void XoaNXB(string maNXB)
        {
            db.ThuThiSQL("delete from tbNXB where MaNXB=N'" + maNXB + "'");
        }

        public void LoadLenDataGV(DataGridView dg)
        {
            db.LoadLenDG(dg, "select * from tbNXB");
        }

        public bool KiemTraDL(string maNXB)
        {
            return db.KiemTra("select count(*) from tbNXB where MaNXB=N'"+maNXB+"'");
        }

        public void LoadLenCB(ComboBox cbNXB)
        {
            db.LoadLenCombobox(cbNXB, "select TenNXB from tbNXB", 0);
        }

        public string LoadLenMaNXB(string MaNXB, string TenNXB)
        {
            MaNXB = db.LoadLenLable("select MaNXB from tbNXB where TenNXB=N'" + TenNXB + "'");
            return MaNXB;
        }

        public string LoadLenTenNXB(string MaNXB, string TenNXB)
        {
            TenNXB = db.LoadLenLable("select TenNXB from tbNXB where MaNXB=N'" + MaNXB + "'");
            return TenNXB;
        }
    }
}
